<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>设置初始条码</title>
    <meta name="decorator" content="default"/>
    <script src="${ctxStatic}/lodop/LodopFuncs.js" type="text/javascript"></script>
    <script type="text/javascript">
        jQuery.validator.addMethod("isSnBegin", function(value, element) {
            var length = value.length;
            var code = /^(([a-zA-Z]|[0-9])*)+([0-9]*)+([0-9])$/;
            return this.optional(element) || (length >= 1 && code.test(value));
        }, "请填写正确的条码号，必须以数字结尾,最后一位大于等于0");


        $().ready(function () {
            $("#snPrintForm").validate({
                submitHandler: function (form) {   //表单提交句柄,为一回调函数，带一个参数：form
                    setUpStartBanId();
                }
            });
        });
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active"><a href="${ctx}/book/purchase/gotoSetUpStartBanId">设置起始条码</a></li>
</ul>
<br/>
<form:form id="snPrintForm" method="get" class="form-horizontal">
    <div>
        <div class="control-group">
            <table border="1" width="50%">
                <thead style="background-color: #2fa3e6;color: #fff;">
                    <td width="50%">设置用户</td>
                    <td width="50%">起始条码号</td>
                </thead>
                <c:forEach items="${bookBanList}" var="bookBan">
                    <c:if test="${bookBan.user eq loginName}">
                        <c:set var="isHas" value="true"></c:set>
                        <tr>
                            <td>${bookBan.user}</td>
                            <td>
                                <input name="snBegin" type="text" maxlength="50" value="${bookBan.banId}" class="required isSnBegin"/>
                            </td>
                        </tr>
                    </c:if>
                    <c:if test="${bookBan.user ne loginName}">
                        <tr>
                            <td>${bookBan.user}</td>
                            <td>${bookBan.banId}</td>
                        </tr>
                    </c:if>
                </c:forEach>

                <c:if test="${!isHas}">
                    <tr>
                        <td>${loginName}</td>
                        <td>
                            <input name="snBegin" type="text" maxlength="50" value="${snBegin}" class="required isSnBegin"/>
                        </td>
                    </tr>
                </c:if>

            </table>
        </div>
        <div class="form-actions">
            <input id="btnSubmit" class="btn btn-primary" type="submit" onclick="" value="提交"/>&nbsp;
        </div>
    </div>
</form:form>
<script type="text/javascript">
    function setUpStartBanId() {
        var startsn = $("[name='snBegin']").val();
        $.ajax({
            type: "POST",
            url: "${ctx}/book/purchase/setUpStartBanId",
            data: {startsn: startsn},
            dataType: "json",
            success: function (data) {
                parent.$.jBox.info(data.msg, '提示', {
                    closed: function () {
                        location.reload();
                    }
                });
            }
        });
    }
</script>
</body>
</html>